#include "Bullet.h"

void Bullet::Set(float x, float y, float angle)
{
	_Coor._x = x;
	_Coor._y = y;
	_r = 5;
	_speed = 1;
	_angle = angle;
	_timer.SetTime(3);
	_live = true;
}

void Bullet::Move()
{
	if (_timer.IsTimeOut())
	{
		double radian = 3.1415926 * _angle / 180;
		_Coor._x += _speed * cos(radian);
		_Coor._y += _speed * sin(radian);
	}
	if (_Coor._x < 0 || _Coor._x > WindowWidth
		|| _Coor._y <0 || _Coor._y > WindowHeight)
	{
		_live = false;
	}
}

void Bullet::Draw(HDC hdc)
{
	HBRUSH hBrushRed = CreateSolidBrush(RGB(255, 0, 0));
	HBRUSH hBrush = (HBRUSH)SelectObject(hdc, hBrushRed);

	Rectangle(hdc,
		int(_Coor._x - _r), int(_Coor._y - _r),
		int(_Coor._x + _r), int(_Coor._y + _r)
	);

	SelectObject(hdc, hBrush);
	DeleteObject(hBrushRed);
}

bool Bullet::IsLive()
{
	return _live;
}
